{% extends "site_base.html" %}

{% block head_title %}{{ block.super }}: {{ wall.name }}{% endblock %}

{% block body %}

<h2 align="center">Edit an item from {{ wall.name }}</h2>
<p>
<form action="." method="POST">
<table>
{{ form.as_table }}
</table>
<span id="chars_left"></span> characters left.
<input type="submit" value="Submit"/>
</form>
</p>
<hr/>
<p>
Never mind. <a href="/wall/home/{{ wall.slug }}/">Go back to the Wall</a>.
</p>
{% endblock %}



{% block extra_body %}
    <script>
        $(document).ready(function() {
            function update_chars_left() {
                var max_len = {{ max_item_length }};
                var textarea = $('#id_posting')[0];
                var tweet_len = textarea.value.length;
                if (tweet_len >= max_len) {
                    textarea.value = textarea.value.substring(0, max_len); // truncate
                    $('#chars_left').html("0");
                } else {
                    $('#chars_left').html(max_len - tweet_len);
                }
            }
            $('#id_posting').keyup(function() {
                update_chars_left();
            });
            update_chars_left();
            $('#id_posting').focus();
            {% if reply %}
            var offset = {{ reply|length }} + 2;
            var textarea = $('#id_posting')[0];
            if (textarea.setSelectionRange) { // Safari, Firefox
                textarea.setSelectionRange(offset, offset);
            } else if (textarea.createTextRange) { // IE
                var range = textarea.createTextRange();
                range.collapse(true);
                range.moveEnd('character', offset);
                range.moveStart('character', offset);
                range.select();
            }
            {% endif %}
        });
    </script>
    
    
{% endblock %}
